package com.ourcraft.informationcollectionsystem.entity;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ourcraft.informationcollectionsystem.utils.statusCode.CompanyRecordStatus;
import lombok.*;

@Data
@NoArgsConstructor
@TableName("Company")
public class Company {
    @TableId(type = IdType.AUTO)
    private Integer companyId;
    private Integer userId;
    private String companyCity;
    private String companyLocation;
    private String companyInstCode;
    private String companyChineseName;
    private String companyEnglishName;
    private String companyNature;
    private String companyIndustry;
    private String companyBusiness;
    private String companyContacts;
    private String companyAddress;
    private String companyPostcode;
    private String companyPhone;
    private String companyFax;
    private String companyEmail;
    @Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE)
    private CompanyRecordStatus companyRecordStatus;

    public Company(Integer userId) {
        this.userId = userId;
        this.companyRecordStatus = CompanyRecordStatus.NOT_FILL;
    }

    public Company(JSONObject param) {
        this.companyId = param.getIntValue("companyId");
        this.userId = param.getIntValue("userId");
        this.companyChineseName = param.getString("companyChineseName");
        this.companyEnglishName = param.getString("companyEnglishName");
        this.companyInstCode = param.getString("companyInstCode");
        this.companyPostcode = param.getString("companyPostcode");
        this.companyLocation = param.getString("companyLocation");

        if (this.companyLocation != null) {
            int provinceIndex = companyLocation.indexOf("/");
            // 如果找到了“/”，进行截取
            if (provinceIndex != -1) {
                this.companyCity = companyLocation.substring(0, provinceIndex);
            } else {
                this.companyCity = null;
            }
        } else this.companyCity = null;

        this.companyIndustry = param.getString("companyIndustry");
        this.companyNature = param.getString("companyNature");
        this.companyBusiness = param.getString("companyBusiness");
        this.companyContacts = param.getString("companyContacts");
        this.companyPhone = param.getString("companyPhone");
        this.companyAddress = param.getString("companyAddress");
        this.companyFax = param.getString("companyFax");
        this.companyEmail = param.getString("companyEmail");

        this.companyRecordStatus=null;
    }
    public void setCompanyRecordStatus(Integer companyRecordStatus) {
        this.companyRecordStatus = CompanyRecordStatus.build(companyRecordStatus);
    }

    public void setCompanyRecordStatus(CompanyRecordStatus companyRecordStatus) {
        this.companyRecordStatus = companyRecordStatus;
    }

    public Integer getCompanyRecordStatus() {
        return companyRecordStatus.status;
    }

    public CompanyRecordStatus getStatus(){
        return companyRecordStatus;
    }
}
